package com.ctbu.tourism.api;

import com.ctbu.tourism.entity.Report;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ReportAPI {

    //新增一条举报用户信息
    @Insert("insert into tb_report(content,ouid,uid) values(#{content},#{ouid},#{uid})")
    Integer addReportU(@Param("content") String content,@Param("ouid") Integer ouid,@Param("uid") Integer uid);

    //新增一条举报帖子信息
    @Insert("insert into tb_report(content,pid,uid) values(#{content},#{pid},#{uid})")
    Integer addReportP(@Param("content") String content,@Param("pid") Integer pid,@Param("uid") Integer uid);


    //删除一条举报信息
    @Delete("delete from tb_report where id=#{id}")
    Integer deleteReport(@Param("id") Integer id);

    //某条帖子的所有举报用户的id
    @Select("select uid from tb_report where pid=#{pid}")
    List<Integer> getReportPostUIDs(@Param("pid") Integer pid);
    //某个用户的所有举报用户的id
    @Select("select uid from tb_report where ouid=#{ouid}")
    List<Integer> getReportUserUIDs(@Param("ouid") Integer ouid);

    //查询所有待审核帖子
    @Select("select tb_report.*,tb_post.title as post_title,tb_post.content as post_content,tb_user.nickname as post_nickname from tb_report join tb_post on tb_post.id = tb_report.pid join tb_user on tb_user.id = tb_post.uid and tb_report.status = \"待审核\"")
    List<Report> getReportPostStatus();

    //查询所有待审核用户
    @Select("select tb_report.*,tb_user.nickname as post_nickname from tb_report join tb_user on tb_user.id = tb_report.ouid and tb_report.status = \"待审核\"")
    List<Report> getReportUserStatus();

    //查询待审核帖子总数
    @Select("select count(*) from tb_report join tb_post on tb_post.id = tb_report.pid join tb_user on tb_user.id = tb_post.uid and tb_report.status = \"待审核\"")
    Integer getReportPostSum();

    //查询待审核用户总数
    @Select("select count(*) from tb_report join tb_user on tb_user.id = tb_report.ouid and tb_report.status = \"待审核\"")
    Integer getReportUserSum();

    @Update("update tb_report set status = \"审核完成\" where id = #{id}")
    Integer updateReportStatus(@Param("id") Integer id);

}
